import {
  User
} from '../../model/user-model.js';

var user = new User();

import {
  Token
} from '../../utils/token.js';

var token = new Token();

import {
  Company
} from '../../model/company-model.js';
var company = new Company();

import {
  Note
} from '../findworker/note-model.js';

var note = new Note();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    curCard:2
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '发布',
    })
    wx.hideNavigationBarLoading();
    wx.stopPullDownRefresh();
  },

  toPubOld: function () {

    wx.navigateTo({
      url: '/pages/pubold/index',
    })
  },
	toWorkCrowd() {
		wx.navigateTo({
		  url: '/pages/workCrowd/index',
		})
	  },

  toPubLet: function () {

    wx.navigateTo({
      url: '/pages/publet/index',
    })
  },


  selectCur(e){
    const index = e.currentTarget.dataset.index
    this.setData({
      curCard:index
    })
  },
  


  toTaskjob: function () {




    var that = this;

    var params = {};

    token.verify(

      user.checkBind((data) => {

        if (data.isbind) {

          var city;
          city = wx.getStorageSync('city');
          var paramsPubNote = {
            city: city
          };
          note.getPubNoteInit((data) => {
            console.log("data", data.noteinfo)
            if (data.noteinfo && data.noteinfo.id) {
              wx.redirectTo({
                url: '/pages/findjob/index'
              })
            } else {
              wx.navigateTo({
                url: "/pages/mynote/index"
              })
            }
          }, paramsPubNote)
        } else {

          wx.navigateTo({
            url: "/pages/register/index"
          })

        }



      }, params)

    )



    /*
  
        wx.navigateTo({
          url: "/pages/taskjob/index"
        })
          */

  },

  toLogin: function (e) {


    var that = this;

    var params = {};

    token.verify(

      user.checkBind((data) => {

        if (data.isbind) {
          var ctoken = wx.getStorageSync('ctoken');

          if (ctoken) {
            var params = {
              ctoken: ctoken
            };

            company.checkLogin((data) => {

              if (data.error == 0) {
                wx.navigateTo({
                  url: "/pages/companycenter/index"
                })

              } else {
                wx.navigateTo({
                  url: "/pages/companylogin/index"
                })

              }


            }, params);




          } else {

            wx.navigateTo({
              url: "/pages/companylogin/index"
            })

          }




        } else {

          wx.navigateTo({
            url: "/pages/register/index"
          })

        }



      }, params)

    )




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    this.onLoad();
  },

  //分享效果
  onShareAppMessage: function () {
    var that = this;
    return {
      title: '发布',
      path: '/pages/switchrole/index'
    }
  },




})
